
import datetime
from .db import cursor, conn
from utils.print_message import print_message

# 根据用户id和模型id获取对应的数据信息
def get_user_evaluation_by_user_id_and_llm_id(user_id, llm_id):
    cursor.execute("select * from user_evaluation where user_id = %s and llm_id = %s", (user_id, llm_id))
    return cursor.fetchone()


# 插入数据
def insert_user_evaluation(user_evaluation_class):
    data = user_evaluation_class.json()
    now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    data['create_time'] = now
    data['update_time'] = now

    columns = ", ".join(data.keys())
    placeholders = ", ".join(["%s"] * len(data))
    sql = f"INSERT INTO user_evaluation ({columns}) VALUES ({placeholders})"
    params = tuple(data.values())
    
    # complete_sql = cursor.mogrify(sql, params)  # 移除.decode('utf-8')
    # print_message(f"完整SQL:{complete_sql}")

    cursor.execute(sql, params)
    conn.commit()
    return cursor.rowcount